package P150;

import java.util.*;

/**
 * @author LiangMu
 * @version \$Id: P40.java, v 0.1, 2024年07月06日 02:01 LiangMu Exp $$
 */
public class P40 {

    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String key = String.valueOf(chars);
            List<String> val = map.getOrDefault(key, new ArrayList<>());
            val.add(str);
            map.put(key, val);
        }
        return new ArrayList<>(map.values());
    }

}
